

var namecardlistName=null;
$(function (){
    namecardlistName=$("#nameCardList");
    //名片夹名字验证
    namecardlistName.blur(function (){
        var reg="^[\u4E00-\u9FA5A-Za-z0-9]{1,20}$";
        if(namecardlistName.val().trim().match(reg)){
            $.ajax({
                url: "/nameCardList/nameYZ",
                data: {"namecardlistName":namecardlistName.val().trim()},
                dataType: "json",
                type: "post",
                success:function (result){
                    if(!result){
                        namecardlistName.next().html(" 格式正确");
                    }else {
                        namecardlistName.next().html("名称已存在");
                    }
                }

            })
        }else if(namecardlistName.val()===''){
            namecardlistName.next().html(" 名称不能为空");
        }else {
            namecardlistName.next().html(" 格式错误");
        }
    })

    namecardlistName.focus(function (){
        namecardlistName.next().html("*");
    })
    namecardlistName.mouseout(function (){
        console.log($("#nameCardList").trim().val())
    })
})





var vm=new Vue({
    el:"#addNameList",
    data: {
        nameCardList:""
    },
    methods: {
        add(){
            var flag = true;
            if (namecardlistName.next().html() !== " 格式正确") {
                flag = false;
            }
            //添加
            if (flag){
                // console.log(vm.nameCardList)
                var nameCard=vm.nameCardList;
                var nameCard1=nameCard.trim();
                // console.log(nameCard1)
                axios({
                    method:'POST',
                    url:'http://localhost:8099/nameCardList/addNameCardList',
                    data: {
                        "namecardlistName":nameCard1,
                    }
                }).then(function (result) {
                    if(result){
                        alert("添加成功");
                        location.href="nameCardList.html"
                    }else {
                        alert("添加失败")
                    }
                }).catch(function (reason) {
                    console.log(reason);
                })
            }else {
                alert("填写有误");
            }

        }

    } ,
    //页面加载完自动执行
    mounted() {
        //
    }


})

